//
//  ViewController.m
//  DiariosArgentinosV2
//
//  Created by Federico Muñecas on 12/11/12.
//  Copyright (c) 2012 Federico Muñecas. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize clarinViewController;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    self.clarinViewController = nil;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)insertarVistaClarin {
    if (self.clarinViewController == nil){
        self.clarinViewController =
        [[ClarinViewController alloc] initWithNibName:@"ClarinViewController" bundle:nil];
    }
    
    [self.view insertSubview:self.clarinViewController.view atIndex:4];
    
}

-(void)insertarVistaPrincipal {
        [clarinViewController.view removeFromSuperview];
}

- (IBAction)switchViewsClarin:(id)sender {
    
    // Inicia el bloque de animación
    [UIView beginAnimations:@"View Flip" context:nil];
    // Duración
    [UIView setAnimationDuration:1.25];
    // Tipo de animación: Lento al principio y al final
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    

    
    if ([self isViewVisible:self.clarinViewController.view]){
    	// Transición animada
        [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
                               forView:self.view cache:YES];
        
        [clarinViewController.view removeFromSuperview];
        self.clarinViewController = nil;
        [self insertarVistaPrincipal];
    }else{
    	// Transición animada
        [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp
                               forView:self.view cache:YES];
        
        [self insertarVistaClarin];
    }

    
    // Termina el bloque de animación
    [UIView commitAnimations];
}
- (BOOL)isViewVisible:(UIView *)view {
    return view.superview != nil;
}


@end
